package com.logic.idevice.impl.dt51

import android.content.Context
import androidx.lifecycle.Lifecycle
import com.logic.idevice.IUHFSetting
import com.orhanobut.hawk.Hawk
import com.sinopec.basemodule.constants.PreferencesConstant
import com.ubx.usdk.rfid.RfidManager

/**
 * @author lwj
 * @ClassName: DT51Setting
 * @Description: DT51手持设置模块
 */
class DT51Setting(
    val refreshPowerUi: (Int) -> Unit,
    val refreshTemUi: (String) -> Unit,
) : IUHFSetting {
    val TAG = "DT51-" + DT51Setting::class.java.simpleName
    var mRfidManager: RfidManager? = null
    private var RFID_INIT_STATUS = false

    companion object {

        //功率缓存
        var pow: Int
            get() = Hawk.get("DT51_pow") ?: 0
            set(value) {
                Hawk.put("DT51_pow", value)
            }


//        enum class ScanAreaFlag {
//            EPC, USER
//        }
//
//        //使用 epc标识
//        var useEpcFlag: ScanAreaFlag
//            get() = Hawk.get("Kv7Setting_useEPCFLAG") ?: ScanAreaFlag.USER
//            set(value) {
//                Hawk.put("Kv7Setting_useEPCFLAG", value)
//            }


    }

    override fun init(context: Context, lifecycle: Lifecycle) {
        // 在异步回调中拿到RFID实例
/*        USDKManager.getInstance().init { status ->
            if (status) {
                Log.d(TAG, "initRfid()  success.")
                RFID_INIT_STATUS = true
                mRfidManager = USDKManager.getInstance().rfidManager
            } else {
                Log.d(TAG, "initRfid  fail.")
            }
        }*/
    }

    override fun openVoince(): Boolean {
        return PreferencesConstant.getInstance().beeper_model == 0
    }

    override fun save(power: Int, openVoince: Boolean) {
        //保存并设置功率
        pow = power
       // mRfidManager!!.setOutputPower(power.toByte())
        //2.保存提示音状态
        PreferencesConstant.getInstance().beeper_model = if (openVoince) 1 else 0
    }

    override fun readTemperature(): String {
        return ""
    }

    override fun refreshTemperature() {
        refreshTemUi(readTemperature())
    }

    override fun readPower(): Int {
        return pow
    }

    override fun refreshPower() {
        refreshPowerUi(readPower())
    }
}